<template>
  <div class="app-container initial-box">
    <el-row :gutter="10" class="mb8">
      <div class="initial-oper">
        <div class="init-left">
          <el-col :span="1.5">
            <el-select
              v-model="selectwarehouse"
              placeholder="请选择仓库"
              @change="warehouseChange"
            >
              <el-option
                v-for="item in optionswarehouse"
                :key="item.uniqueId"
                :label="item.name"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              v-hasPermi="['wm:initial:sync']"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handlesyn"
              :disabled="selectwarehouse == ''"
              >同步物料</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-remove-outline"
              size="mini"
              @click="handlEmpty"
              :disabled="selectwarehouse == ''"
              v-hasPermi="['wm:initial:dump']"
              >清空</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="mini"
              @click="handleImport"
              v-hasPermi="['wm:initial:Import']"
              :disabled="selectwarehouse == ''"
              >导入</el-button
            >
          </el-col>
          <el-col :span="1.5" style="margin-right: 15px">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['wm:initial:export']"
              :disabled="selectwarehouse == ''"
              >导出</el-button
            >
          </el-col>
          <el-col :span="1.5" style="position: relative">
            <el-input
              placeholder=""
              disabled
              prefix-icon="el-icon-date"
              v-model="period.time"
            >
            </el-input>
            <span
              v-if="selectwarehouse !== '' && period.time !== ''"
              style="
                position: absolute;
                right: 35px;
                top: 4px;
                font-size: 14px;
                color: #999;
              "
              >期间</span
            >
          </el-col>

          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-check"
              size="mini"
              :disabled="selectwarehouse == '' && period.time == ''"
              :loading="loadCheck.checkinLoading"
              @click="handleWarehousing"
              v-hasPermi="['wm:initial:checkin']"
              >{{ loadCheck.checkinTitle }}</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              :loading="loadCheck.backLoading"
              icon="el-icon-refresh-left"
              size="mini"
              :disabled="selectwarehouse == ''"
              @click="handleRevoke"
              v-hasPermi="['wm:initial:revoke']"
              >{{ loadCheck.backTitle }}</el-button
            >
          </el-col>
        </div>
        <div class="init-right">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-c-scale-to-original"
              size="mini"
              :disabled="formInput.wmInSalveList.length == 0"
              v-hasPermi="['wm:initial:batch']"
              @click="handleBatchNumber"
              >批号设置</el-button
            >
          </el-col>
        </div>
      </div>
    </el-row>
    <!-- 物料数据 -->
    <div class="inv-box">
      <el-form ref="formInput" :model="formInput" :rules="rules">
        <el-table
          :data="formInput.wmInSalveList"
          border
          :height="maxHeight"
          v-loading="loading"
          ref="table"
          :key="Math.random()"
          :row-class-name="tableRowClassName"
          highlight-current-row
          @row-click="handleFocus"
        >
          <el-table-column type="index" width="60" align="center" label="序号">
          </el-table-column>
          <el-table-column label="物料编码" align="center" prop="invCode">
          </el-table-column>
          <el-table-column label="物料名称" align="center">
            <template slot-scope="scope">
              <div class="con-spec" v-if="fmConfig.attrMerge == 'true'">
                <span>{{ scope.row.invName }}{{ scope.row.invAttribute }}</span>
              </div>
              <el-form-item v-if="fmConfig.attrMerge == 'false'">
                <div class="select-name">
                  <span>{{ scope.row.invName }}</span>
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            :label="fmConfig.attrAlias"
            v-if="fmConfig.attrMerge == 'false'"
            width="150"
            align="center"
          >
            <template slot-scope="scope">
              <el-form-item>
                <span>{{ scope.row.invAttribute }}</span>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            label="主计量"
            align="center"
            prop="unitName"
            width="75"
          >
          </el-table-column>
          <el-table-column
            label="批号"
            align="center"
            prop="batchNumber"
            width="180"
          >
            <template slot-scope="scope">
              <el-form-item>
                <el-input
                  v-model="scope.row.batchNumber"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <!-- 特殊属性 -->
          <el-table-column
            :label="fmConfig.property[0]"
            width="100"
            v-if="fmConfig.property.length > 0"
          >
            <template slot-scope="scope">
              <el-form-item>
                <el-input
                  v-model="scope.row.f1"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            :label="fmConfig.property[1]"
            width="100"
            v-if="fmConfig.property.length > 1"
          >
            <template slot-scope="scope">
              <el-form-item>
                <el-input
                  v-model="scope.row.f2"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            :label="fmConfig.property[2]"
            width="100"
            v-if="fmConfig.property.length > 2"
          >
            <template slot-scope="scope">
              <el-form-item>
                <el-input
                  v-model="scope.row.f3"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            :label="fmConfig.property[3]"
            width="100"
            v-if="fmConfig.property.length > 3"
          >
            <template slot-scope="scope">
              <el-form-item>
                <el-input
                  v-model="scope.row.f4"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            :label="fmConfig.property[4]"
            width="100"
            v-if="fmConfig.property.length > 4"
          >
            <template slot-scope="scope">
              <el-form-item>
                <el-input
                  v-model="scope.row.f5"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            label="期初数量"
            align="center"
            prop="quantity"
            width="150"
          >
            <template slot-scope="scope">
              <el-form-item
                class="text-right"
                :prop="'wmInSalveList.' + scope.$index + '.quantity'"
                :rules="rules.quantity"
              >
                <el-input
                  v-model="scope.row.quantity"
                  style="text-align: right"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
                    <el-table-column label="单价" align="center" prop="price" width="150">
            <template slot-scope="scope">
              <el-form-item
                class="text-right"
                :prop="'wmInSalveList.' + scope.$index + '.price'"
                :rules="rules.price"
              >
                <el-input
                  v-model="scope.row.price"
                  style="text-align: right"
                  @input="formatDecimal(scope.$index, scope.row)"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="金额" align="center" width="150">
            <template slot-scope="scope">
              <el-form-item class="text-right">
                <el-input
                  v-model="scope.row.amount"
                  disabled
                  style="text-align: right"
                >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding"
            width="150"
          >
            <template slot-scope="scope">
              <div class="public-btn">
                <el-button
                  size="mini"
                  type="text"
                  :disabled="!scope.row.light"
                  class="basic-see"
                  @click.stop="handleUpdate(scope.$index, scope.row)"
                  >保存
                </el-button>
                <el-button
                  size="mini"
                  :disabled="copyStatus"
                  type="text"
                  @click.stop="handleCopy(scope.$index, scope.row)"
                  >复制
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </div>
    <!-- 分页信息 -->
    <pagination
      v-if="formInput.wmInSalveList.length > 0 && total > 20"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="warehouseChange(whCode)"
    />
    <!-- 物料导入对话框 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="
          upload.url +
          '?updateSupport=' +
          upload.updateSupport +
          '&whCode=' +
          upload.whCode
        "
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>

        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 入库对话框 -->
    <!-- <el-dialog
      title="入库"
      :visible.sync="openWareStatus"
      width="600px"
      @close="close"
    >
      <el-form
        ref="wareHousingForm"
        :model="wareHousingForm"
        label-width="85px"
        :rules="rules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item prop="workType" label="业务类型">
              <el-select
                v-model="selectworkType"
                placeholder="请选择"
                @change="workTypeChange"
              >
                <el-option
                  v-for="item in optionsworkType"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="wareHousingForm.remarks"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库日期" prop="inWmDate">
              <el-date-picker
                class="input-data"
                type="date"
                placeholder="选择日期"
                v-model="wareHousingForm.inWmDate"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="每单条数" prop="num">
              <el-input v-model="wareHousingForm.num"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="foot-star">
        <div class="star-con">
          <i class="el-icon-star-on"></i>
          温馨提示：入库成功后，请到入库单据批量审核单据完成入库！
        </div>
        <el-button
          type="primary"
          @click="submitWareHousingForm('wareHousingForm')"
          >确定</el-button
        >
      </div>
    </el-dialog> -->
    <!-- 批号设置 -->
    <el-dialog title="批号设置" :visible.sync="batchNumberDialog" width="400px">
      <el-form
        :rules="rules"
        :model="formBatchNumber"
        ref="formBatchNumber"
        label-width="68px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item
              prop="batchNumber"
              label="批号"
              style="margin-bottom: 15px"
            >
              <el-input v-model="formBatchNumber.batchNumber"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="batchNumberChange()">确定</el-button>
        <el-button @click="batchNumberCancel()">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import {
  listWarehouses,
  checkWarehouses,
  SyncMaterial,
  updateMaterial,
  addMaterial, //新增（复制）
  exportMaterial,
  importMateria,
  invoiceType,
  addInWm,
  setBatchNumber,
  emptyInitial,
  blanceAvailable, //期间
  revokeInitial, //撤回
} from "../../api/initial";
import axios from "axios";
//输入是否为数字效验
import { isAccord } from "@/utils/cingsoft";
export default {
  name: "Initial",
  data() {
    // 数量输入效验
    var checkOutQuantity = (rule, value, callback) => {
      if (!value) {
        return callback(new Error(""));
      }
      if (!isAccord(value)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };

    // 单价输入效验
    var checkOutPrice = (rule, value, callback) => {
      if (!value) {
        return callback(new Error(""));
      }
      if (!isAccord(value)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };

    return {
      loading: true,
      //数量编辑input状态
      disCuarent: true,
      clickIndex: "",
      //仓库选择
      optionswarehouse: [],
      selectwarehouse: "",
      //当前数据index
      upadtateIndex: "",
      //复制按钮状态
      copyStatus: false,
      //点击高亮
      currentStatus: false,
      //期间
      period: {
        data: "",
        time: "",
      },
      //执行提示
      loadCheck: {
        checkinTitle: "入库",
        checkinLoading: false,
        backTitle: "撤回",
        backLoading: false,
      },

      //单据参数
      fmConfig: {
        //数量小数位数
        decimalQuantity: "2",
        //单价小数位数
        decimalPrice: "2",
        //规格合并
        attrMerge: "false",
        //规格别名
        attrAlias: "型号规格",
        //特殊属性
        property: [],
      },
      // 物料查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
      },
      //物料数据
      formInput: {
        wmInSalveList: [],
      },
      //物料数据最大高度
      maxHeight: null,
      //仓库名称
      whName: "",
      //仓库code
      whCode: "",
      // 统一修改批号数据
      batchNumberDialog: false,
      formBatchNumber: {
        batchNumber: "",
        whCode: "",
      },
      // 物料导入参数
      upload: {
        // 是否显示弹出层（物料信息导入）
        open: false,
        // 弹出层标题（物料信息导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        //仓库code
        whCode: "",
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/wm/initial/importData",
      },
      rules: {
        quantity: [
          {
            required: true,
            trigger: "blur",
          },
        ],
        price: [
          {
            required: true,
            trigger: "blur",
          },
        ],
        batchNumber: [
          {
            required: true,
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    // 初始化仓库列表
    this.getHouselList();
  },
  methods: {
    //仓库列表
    getHouselList() {
      this.loading = true;
      listWarehouses().then((res) => {
        if (res.code == 200) {
          this.loading = false;
          this.optionswarehouse = res.rows;
        }
      });
    },

    // 仓库选择
    warehouseChange(code) {
      // 仓库配置
      let houseMsg = null;
      this.optionswarehouse.forEach((item) => {
        if (item.code == code) {
          houseMsg = item;
        }
      });
      if (houseMsg.configMap !== null) {
        // 数量小数位数
        if (houseMsg.configMap["precision.quantity"] !== "null") {
          this.fmConfig.decimalQuantity =
            houseMsg.configMap["precision.quantity"];
        }
        if (houseMsg.configMap["precision.price"] !== "null") {
          this.fmConfig.decimalPrice = houseMsg.configMap["precision.price"];
        }
        //特殊属性
        if (houseMsg.configMap["inv.property"] !== "null") {
          this.fmConfig.property =
            houseMsg.configMap["inv.property"].split(",");
        }
        // 合并规格
        if (houseMsg.configMap["inv.attr.merge"] !== "null") {
          this.fmConfig.attrMerge = houseMsg.configMap["inv.attr.merge"];
        }
        //规格别名
        if (houseMsg.configMap["inv.attr.alias"] !== "null") {
          this.fmConfig.attrAlias = houseMsg.configMap["inv.attr.alias"];
        }
      } else {
        this.resetFmConfig();
      }
      this.whCode = code; //用于导出
      this.upload.whCode = code; //用于导入
      this.whName = houseMsg.name; //仓库名称
      // 开始期间
      this.period.data = houseMsg.startPeriod;
      let time = this.period.data.toString();
      let y = time.slice(0, 4),
        m = time.slice(4, 6);
      this.period.time = y + "-" + m;
      //获取期初数据
      checkWarehouses(this.queryParams, code).then((res) => {
        this.loading = true;
        if (res.code == 200) {
          //仓库对应物料数据
          let wmData = [];
          wmData = JSON.parse(JSON.stringify(res.rows));
          wmData.forEach((item) => {
            if (item.quantity !== undefined && item.quantity !== null) {
              item.quantity = parseFloat(item.quantity).toFixed(
                this.fmConfig.decimalQuantity
              );
            }
            if (item.price !== undefined && item.price !== null) {
              item.price = parseFloat(item.price).toFixed(
                this.fmConfig.decimalPrice
              );
            }
            if (item.amount !== undefined && item.amount !== null) {
              item.amount = parseFloat(item.amount).toFixed(2);
            }
          });
          this.formInput.wmInSalveList = wmData;
          this.total = res.total;
          if (this.formInput.wmInSalveList.length >= 20) {
            //条数总数大于显示出现滚动条
            this.maxHeight = `${document.documentElement.clientHeight}` - 215;
          } else {
            this.maxHeight = null;
          }
          this.loading = false;
        }
      });
    },

    //同步物料
    handlesyn() {
      this.loading = true;
      (this.queryParams.pageNum = 1),
        (this.queryParams.pageSize = 100),
        (this.queryParams.whCode = this.selectwarehouse);
      SyncMaterial(this.queryParams)
        .then((res) => {
          if (res.code == 200) {
            if (res.rows.length !== 0) {
              let wmData = [];
              wmData = JSON.parse(JSON.stringify(res.rows));
              wmData.forEach((item) => {
                if (item.quantity !== undefined && item.quantity !== null) {
                  item.quantity = parseFloat(item.quantity).toFixed(
                    this.fmConfig.decimalQuantity
                  );
                }
                if (item.price !== undefined && item.price !== null) {
                  item.price = parseFloat(item.price).toFixed(
                    this.fmConfig.decimalPrice
                  );
                }
                if (item.amount !== undefined && item.amount !== null) {
                  item.amount = parseFloat(item.amount).toFixed(2);
                }
              });
              this.formInput.wmInSalveList = wmData;
              this.msgSuccess("同步物料成功");
              this.total = res.total;
            } else {
              this.formInput.wmInSalveList = [];
              this.msgError("物料信息为空");
            }
            this.loading = false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    // 清空按钮操作
    handlEmpty() {
      this.$confirm(
        "是否清空" + " " + this.whName + " " + "物料信息?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          return emptyInitial({ whCode: this.whCode });
        })
        .then((res) => {
          this.warehouseChange(this.whCode);
          this.msgSuccess("清空成功");
        });
    },

    //撤回
    handleRevoke() {
      this.$confirm(
        "是否撤回" + " " + this.whName + " " + "入库信息?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.loadCheck.backTitle = "执行中";
          this.loadCheck.backLoading = true;
          return revokeInitial({ whCode: this.whCode });
        })
        .then((res) => {
          this.loadCheck.backTitle = "撤回";
          this.loadCheck.backLoading = false;
          this.msgSuccess("撤回成功");
        })
        .catch(() => {
          this.loadCheck.backTitle = "撤回";
          this.loadCheck.backLoading = false;
        });
    },

    // 保存渲染
    formatDecimal(index, data) {
      this.upadtateIndex = index;
      if (
        this.formInput.wmInSalveList[index].price !== "" &&
        this.formInput.wmInSalveList[index].quantity !== "" &&
        isAccord(this.formInput.wmInSalveList[index].price) &&
        isAccord(this.formInput.wmInSalveList[index].quantity)
      ) {
        this.formInput.wmInSalveList[index].amount = (
          this.formInput.wmInSalveList[index].price *
          this.formInput.wmInSalveList[index].quantity
        ).toFixed(2);
      } else {
        this.formInput.wmInSalveList[index].amount = "0.00";
      }
      data.light = true; //新增高亮元素控制保存按钮
    },

    //保存
    handleUpdate(index, data) {
      this.$refs["formInput"].validate((valid) => {
        if (valid) {
          data.whCode = this.whCode;
          updateMaterial(data)
            .then((res) => {
              //触发保存提交
              if (res.code == 200) {
                this.formInput.wmInSalveList[index].quantity =
                  res.data.quantity.toFixed(this.fmConfig.decimalQuantity);
                this.formInput.wmInSalveList[index].f1 = res.data.f1;
                this.formInput.wmInSalveList[index].f2 = res.data.f2;
                this.formInput.wmInSalveList[index].f3 = res.data.f3;
                this.formInput.wmInSalveList[index].f4 = res.data.f4;
                this.formInput.wmInSalveList[index].f5 = res.data.f5;
                this.formInput.wmInSalveList[index].version = res.data.version;
                this.formInput.wmInSalveList[index].background =
                  data.background;
                this.msgSuccess("保存成功");
              }
            })
            .catch((err) => {
              this.msgError("保存失败");
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    //复制
    handleCopy(index, data) {
      this.formInput.wmInSalveList.forEach((item) => {
        item.background = false;
      });
      let form = {
        whCode: this.whCode,
        invSortId: data.invSortId,
        uniqueId: data.uniqueId,
        invSortRoot: data.invSortRoot,
        invCode: data.invCode,
        invName: data.invName,
        invAttribute: data.invAttribute,
        unitCode: data.unitCode,
        unitName: data.unitName,
        quantity: data.quantity,
        price: data.price,
        amount: data.amount,
        batchNumber: data.batchNumber,
        f1: data.f1,
        f2: data.f2,
        f3: data.f3,
        f4: data.f4,
        f5: data.f5,
      };
      addMaterial(form).then((res) => {
        this.copyStatus = true;
        if (res.code == 200) {
          let obj = JSON.parse(JSON.stringify(res.data));
          obj.quantity = obj.quantity.toFixed(this.fmConfig.decimalQuantity);
          obj.price = obj.price.toFixed(this.fmConfig.decimalPrice);
          obj.amount = obj.amount.toFixed(2);
          obj.background = true;
          this.formInput.wmInSalveList.splice(index + 1, 0, obj);
          this.msgSuccess("复制物料成功");
          this.copyStatus = false;
        }
      });
    },

    //获取焦点表格变色
    handleFocus(row) {
      this.formInput.wmInSalveList.forEach((item) => {
        item.background = false;
      });
      row.background = true;
    },

    /* 复制表格变色 */
    tableRowClassName({ row, rowIndex }) {
      if (row.background === true) {
        return "light-row";
      }
      return "";
    },

    // 导入按钮操作
    handleImport() {
      this.upload.title = this.whName + "物料信息导入";
      this.upload.open = true;
    },

    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },

    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", {
        dangerouslyUseHTMLString: true,
      });
      this.warehouseChange(this.upload.whCode);
    },

    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    //导出
    handleExport() {
      const queryParams = {
        whCode: this.whCode,
      };
      this.$confirm(
        "是否确认导出" + " " + this.whName + " " + "物料数据项?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return exportMaterial(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },

    //批号设置
    handleBatchNumber() {
      this.batchNumberDialog = true;
      this.formBatchNumber.batchNumber = "";
    },

    //确定设置批号
    batchNumberChange() {
      this.$refs["formBatchNumber"].validate((valid) => {
        if (valid) {
          this.formBatchNumber.whCode = this.whCode;
          setBatchNumber(this.formBatchNumber).then((res) => {
            if (res.code == 200) {
              this.warehouseChange(this.whCode);
              this.msgSuccess("批号设置成功");
              this.batchNumberDialog = false;
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    //取消修改批号
    batchNumberCancel() {
      this.batchNumberDialog = false;
    },

    //入库
    handleWarehousing() {
      this.$confirm(
        "是否确定" +
          " " +
          this.whName +
          "入库" +
          " " +
          this.period.data +
          "期间" +
          "?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.loadCheck.checkinTitle = "执行中";
          this.loadCheck.checkinLoading = true;
          return addInWm({ whCode: this.whCode, period: this.period.data });
        })
        .then((res) => {
          this.loadCheck.checkinTitle = "入库";
          this.loadCheck.checkinLoading = false;
          this.msgSuccess("入库成功");
        })
        .catch(() => {
          this.loadCheck.checkinTitle = "入库";
          this.loadCheck.checkinLoading = false;
        });
    },

    //重置表单参数
    resetFmConfig() {
      this.fmConfig = {
        //数量小数位数
        decimalQuantity: "2",
        //单价小数位数
        decimalPrice: "2",
        //特殊属性
        property: [],
      };
    },
  },
};
</script>
<style lang="scss">
.initial-box {
  .initial-oper {
    display: flex;
    justify-content: space-between;
  }
  .el-select {
    input {
      line-height: 28px;
      height: 28px;
      width: 150px;
    }
  }
  .el-input.is-disabled .el-input__inner {
    background: #fff;
    color: #333;
    height: 28px;
    width: 150px;
  }
  .el-table {
    .is-disabled .el-input__inner {
      background: none;
      width: 140px;
    }
  }
  .el-table__body tr.current-row > td {
    background-color: #f5f7fa !important;
  }

  .el-table .light-row {
    background-color: #f5f7fa;
  }

  .public-btn .is-disabled span {
    opacity: 0.5;
  }

  .foot-star {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .star-con {
      font-size: 12px;
      color: #1682e6;

      i {
        color: #1682e6;
      }
    }
  }

  .el-input--medium .el-input__icon {
    line-height: 28px;
  }

  .el-form-item--medium .el-form-item__content {
    margin-right: 10px;
  }

  .el-table--border th:first-child .cell,
  .el-table--border td:first-child .cell {
    padding-left: 0;
  }

  .text-right {
    input {
      text-align: right !important;
    }

    span {
      display: inline-block;
      padding-right: 10px;
      width: 100%;
      text-align: right;
    }
  }

  .inv-box {
    .el-input__inner {
      height: 31px;
      line-height: 0;
      color: #606266;
      background: none;
      border: none;
      border-radius: 0;
      padding: 0;
      text-align: center;
    }

    .cell button {
      padding: 0;
    }

    .el-form-item__content {
      line-height: 30px;
    }

    .el-form-item {
      margin-bottom: 0;
    }

    .el-table--medium td {
      padding: 0 !important;
    }

    .cell {
      height: auto !important;
      line-height: 30px;
      padding-left: 0;
      padding-right: 0;
    }

    // .el-table--enable-row-hover .el-table__body tr:hover>td {
    //   background: none;
    // }

    .el-form-item.is-error .el-input__inner,
    .el-form-item.is-error .el-input__inner:focus,
    .el-form-item.is-error .el-textarea__inner,
    .el-form-item.is-error .el-textarea__inner:focus {
      border: 1px solid #ff4949!important;
    }

    .con-spec {
      display: flex;
      text-align: center;
      justify-content: center;
      word-wrap: break-word;
    }

    .el-table--medium th,
    .el-table--medium td {
      padding: 0 !important;
      text-align: center;
    }
  }
}
</style>
